package com.xxgc.vfc.modules.consumer.university.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.xxgc.vfc.api.dto.SchoolDTO;
import com.xxgc.vfc.api.result.Result;
import com.xxgc.vfc.api.service.ISchoolService;
import com.xxgc.vfc.api.vo.SchoolVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @Author: Sjy
 * @Date :2023/10/20 - 10 - 20 - 10:44
 * 院校接口
 */
//表示这个类里面的接口必须登录才能访问
@SaCheckLogin
@Slf4j
@Api(tags = "学校相关接口")
@Controller
@RestController
@RequestMapping("/university")
public class UniversityController {

    @DubboReference(
            check = false,
            loadbalance = "roundrobin"
    )
    private ISchoolService iSchoolService;

    @ApiOperation(value = "获取学校信息")
    @GetMapping("/getMsg")
    public Result getMsg(HttpServletRequest request){
        String system = request.getHeader("system");
        System.out.println("system = " + system);
        System.out.println("我是工程这边处理的222222222222222");
        return Result.ok().msg("我是工程这边处理的22222222222222");
    }

    @ApiOperation(value = "添加学校")
    @PostMapping("/addSchool")
    public Result addSchool(@RequestBody @Valid SchoolVO schoolVO){
        log.info(schoolVO.toString());
        iSchoolService.addSchool(schoolVO);
        return Result.ok();
    }

    @ApiOperation(value = "通过id查询学校")
    @GetMapping("/getSchoolById")
    public Result<SchoolDTO> getSchoolById(Integer id){
//        log.info("-----------是我处理的------------");
        SchoolDTO schoolDTO = iSchoolService.getSchoolById(id);
        return Result.ok(schoolDTO);
    }
}
